<template>
  <div class="page" style="">
    <div class="print_title">管理结算费用单详情 · 禾美环保</div>
    <p class="title">基本信息</p>
    <a-row type="flex" justify="start" class="content" style="padding: 0 9px;">
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >单据编号:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.billNo }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row>
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >申请人:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.handlerId_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>

      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >申请部门:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.handlerDeptId_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >申请时间:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.createTime }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >项目名称:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.projectId_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>
      <!-- <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >项目编号:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.finalNo }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >合同名称:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.contractId_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>

      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >项目承接人:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.undertaker_dictText }}</p>
          </a-col>
        </a-row>
      </a-col> -->
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >经营团队:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.teamName_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>
      <!-- <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >生产团队:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.productTeamName }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >业绩归属年度:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.year }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >签订单位:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.signUnit_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >业主单位:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.ownerUnit_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>

      <a-col :span="24">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >诉讼说明:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.litigationInstruction }}</p>
          </a-col>
        </a-row>
      </a-col> -->
    </a-row>

    <a-row type="flex" justify="center" v-if="dataSource && dataSource.length" class="performance_information">
      <a-col>
        <p class="title_table">费用信息</p>
      </a-col>
      <a-col :span="24">
        <a-table
          :columns="columns"
          :data-source="dataSource"
          bordered
          :pagination="false"
          size="small"
          :rowClassName="tableRowClass"></a-table>
      </a-col>
    </a-row>

    <!-- 附件信息 -->
    <FileInfor :purchaseFile="purchaseFile" title="任务附件" v-if="purchaseFile && purchaseFile.length"></FileInfor>
    <!-- 流程详情 -->
    <ProcessInfor v-if="formData.bpmStatus !== '1'" :dataHistorySource="dataHistorySource"></ProcessInfor>
  </div>
</template>
<script>
import { getAction } from '@/api/manage'
import FileInfor from '@/components/print/FileInfor.vue' // 审批历史流程列表组件
import ProcessInfor from '@/components/print/ProcessInfor.vue' // 审批历史流程列表组件
import address from '@/components/AddressChoice/address.js'
import { filterMultiDictText, initDictOptions } from '@/components/dict/JDictSelectUtil'
export default {
	props: {
		formData: {
			type: Object,
			default: () => {},
			required: true
    },
		formDataHistory: {
			type: Object,
			default: () => {},
			required: true
    }
	},
  components: {
    FileInfor,
    ProcessInfor
  },
  data() {
    return {
      address,
      filterMultiDictText,
      dictOptions: {},
      dataSource: [], // 物料列表
      columns: [
				{
					title: '序号',
					dataIndex: '',
					key: 'rowIndex',
					width: 45,
					align: 'center',
					customRender: function (t, r, index) {
						return parseInt(index) + 1;
					}
				},
				{
					title: '款项名称',
					align: 'center',
					dataIndex: 'paymentNodeName'
				},
				{
					title: '应收款金额(元)',
					align: 'center',
					dataIndex: 'paymentMoney'
				},
        {
            title: '实收金额(元)',
            align: 'center',
            dataIndex: 'realCollectionPaymentMoney'
          },
          {
            title: '管理费(元)',
            align: 'center',
            dataIndex: 'manageMoney'
          },
          {
            title: '备注',
            align: 'center',
            with: 85,
            dataIndex: 'remark'
          }
			],
			dataHistorySource: [], // 流程列表
			url: {
				list: '/api/erp/audit/manage/erpAuditManageClearingDetail/list', // 子列表
				historyList: '/api/erpmng/act/task/processHistoryList' // 流程历史跟踪接口
			},
			purchaseFile: [], // 附件
      businessFile: []
    };
  },
	watch: {
		formData: {
			handler (val) {
				if (val) {
					this.list()
					this.getHistoryList()
          // this.initDictConfig() // 字典值
          // 获取任务信息
          // if (val.taskId) {
          //   this.getTaskDetail(val.taskId)
          // }
					if (val.file) {
						this.purchaseFile = val.file.split(',')
					}
				}
			},
			immediate: true
		},
		formDataHistory: {
			handler (val) {
				if (val) {
					this.getHistoryList()
				}
			},
			immediate: true
		}
	},
	methods: {
		// 获取列表
		getHistoryList() {
			var params = { processInstanceId: this.formDataHistory.procInsId };// 查询条件
			getAction(this.url.historyList, params).then(res => {
				if (res.success) {
					this.dataHistorySource = res.result.records || res.result
				}
			})
		},

    // 获取任务信息详情
    getTaskDetail (id) {
      var param = {
        id
      }
      getAction('/api/erp/omc/project/erpOmcProjectTaskFinal/queryPageList', param).then((res) => {
          console.log(res)
          if (res.success) {
            if (res.result.records && res.result.records.length) {
              this.$set(this.formData, 'taskId_dictText', res.result.records[0].billNo)
            }
          }
        })
    },

    async initDictConfig() {
        initDictOptions('erp_omc_team_manager,alias_name,id').then(async(res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'teamId', res.result)
          }
        })
        initDictOptions('erp_omc_project,project_name,id').then(async(res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'projectId', res.result)
          }
        })
        initDictOptions('erp_omc_project_task,category_name,id').then(async(res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'taskId', res.result)
          }
        })
        initDictOptions('yjgsnd').then(async(res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'yjgsYear', res.result)
          }
        })
        initDictOptions('tdnd_type').then(async(res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'feeYear', res.result)
          }
        })
        initDictOptions('approval_level').then(async(res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'approvalLevel', res.result)
          }
        })
        initDictOptions('industry_coefficient').then(async(res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'difficultyLevel', res.result)
          }
        })
        initDictOptions('erp_company_files,file_name,id').then(async(res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'signUnit', res.result)
          }
        })
      },

		list () {
			if (!this.formData.id) {
				return false
			}
			var params = {
        mainId: this.formData.id,
        pageSize: 100
			}
			getAction(this.url.list, params).then(res => {
				if (res.success) {
						this.dataSource = res.result.records || res.result
						this.dataSource.forEach((item, index) => {
						item.key = index
					})
				}
      })
		},

		tableRowClass(record, index) {
			console.log('record, index', record, index)
			if (index == 0) {
				return 'rowClass';
			}
      return ''
    },

    getAddress (text) {
      if (!text) {
        return false
      }
      var areaList = text.split(',')
      var areaText = ''
      this.address.map(value => {
        if (areaList[0] && areaList[0] == value.code) {
          areaText = areaText + value.name + '/'
          if (value && value.children && value.children.length) {
            value.children.map(val => {
              if (areaList[1] && areaList[1] == val.code) {
                areaText = areaText + val.name + '/'

                if (val && val.children && val.children.length) {
                  val.children.map(va => {
                    if (areaList[2] && areaList[2] == va.code) {
                      areaText = areaText + va.name
                    }
                  })
                }
              }
            })
          }
        }
      })
      return areaText
    }
	}
};
</script>
<style lang="less" scoped>
.page{
	background: #ffffff;
	padding: 19px 28px 0 28px;
	width: 750px;
	.print_title{
		font-size: 15px;
		font-family: Alibaba PuHuiTi 2.0;
		font-weight: normal;
		color: #000000;
		display: flex;
		align-items: center;
		justify-content: center;
		margin-bottom: 9px;
	}
	.title {
		background: #EEEEEE;
		font-size: 13px;
		font-family: Alibaba PuHuiTi 2.0;
		font-weight: normal;
		color: #000000;
		padding: 11px 9px;
	}
	.title_table{
		font-size: 13px;
		font-family: Alibaba PuHuiTi 2.0;
		font-weight: normal;
		color: #000000;
	}
}
/deep/ .rowClass{
	font-size: 10px;
	font-family: Alibaba PuHuiTi 2.0;
	font-weight: normal;
	color: #000000;
}
/deep/ .ant-table-thead th{
	font-size: 10px;
	font-family: Alibaba PuHuiTi 2.0;
	font-weight: normal;
	color: #000000;
}
/deep/ .ant-table-thead tr{
	background: #EEEEEE;
}
/deep/ .ant-table-small > .ant-table-content > .ant-table-body {
    margin: 0 0px;
}
/deep/ .ant-table-body tr {
	font-size: 10px;
	font-family: Alibaba PuHuiTi 2.0;
	font-weight: normal;
	color: #000000;
}
/deep/ .ant-table-body tr td {
    word-wrap:break-word;
    word-break:break-all;
  }
.content {
  font-size: 13px;
}
</style>
